1. Field of the Invention
The present invention relates to protocol stacks.
2. Description of the Related Art
In a packet switched network, a message to be sent is divided into packets of fixed or variable length. The packets are then sent individually over the network through multiple switches or nodes and then reassembled at a final destination before being delivered to a target device or end user. To ensure proper transmission and re-assembly of the packets at the receiving end, various control data, such as sequence and verification information, is typically appended to each packet in the form of a packet header. At the receiving end, the packets are then reassembled and the message is passed to the end user in a format compatible with the user's equipment.
Most packet switched networks operate according to a set of established protocol layers, collectively defining a protocol stack. The protocol stack is a plurality of interfaced layers. These layers may be defined according to the Open Systems Interconnect (OSI) model, having seven layers (from top to bottom): application, presentation, session, transport, network, data-link and physical. All but the physical layer are typically software, though the network and data-link layer may be firmware and/or hardware. Each layer of the protocol stack exists to perform a specific function, such as addressing, routing, framing and physical transmission of packets. When a packet is to be transmitted over a network from a source system to a destination system, the packet will pass in a logically downward direction through layers of the protocol stack on the source system, and in a logically upward direction through corresponding layers of the protocol stack on the destination system. Each layer passes the packet to the adjacent layer, either up or down the protocol stack depending on whether the packet has been received or is being transmitted.
Each layer of the protocol stack in the transmitting process may add a respective header to the packet, which provides information to the corresponding layer in a receiving process. Thus, as a packet passes down through the protocol stack on a transmitting system, the packet may gain an additional header at each layer. At the bottom of the stack, the transmitting process may then frame the packet and physically transmit it over the network toward its destination. When the packet reaches its destination, the packet will then pass up through the protocol stack of the destination system. Each layer of the protocol stack in the destination system may obtain useful information from its associated header and will strip its header from the packet before passing the packet up to the next layer for processing. At the top of the protocol stack, the application layer typically receives a byte stream from the layer below it, not individual packets. The byte stream may consist of data that consists of a partial packet or data that covers more than one packet. This is very convenient for the application but may impair performance.
The layers at the top of a protocol stack are typically designed to provide end-to-end communication between source and destination machines on the network. For instance, the top layers may provide packet sequence information and encryption. Lower layers of the stack, on the other hand, often provide information to facilitate communication between immediately adjacent machines in the network. For instance, the lower layers in the protocol stack may provide network address information, for use in routing packets through the network.
A variety of standards are known for use in packet switched networks. One of these, the TCP/IP suite, is typically used to manage transmission of packets throughout the Internet and other IP networks. The TCP/IP protocol stack has four layers, generally corresponding to but differing somewhat from the OSI model.
The TCP/IP application layer corresponds to a combination of the application, presentation and session layers of the OSI model. The TCP/IP application layer includes application programs that carry out the functionality of a network device and interface with a user.
The TCP/IP transport layer corresponds to the transport layer of the OSI model. The TCP/IP transport layer allows source and destination machines to carry on a conversation with each other and includes a connection-oriented Transmission Control Protocol (TCP) layer, but may alternatively be a connectionless User Datagram Protocol (UDP) layer. The transport is TCP or UDP, respectively. With UDP, the application layer is aware of individual packets.
The TCP/IP network layer corresponds to the network layer of the OSI model. The TCP/IP network layer provides addressing information to facilitate independent routing of packets within or between networks and also includes other control layers, such as an Internet Control Message Protocol (ICMP) layer and an Address Resolution Protocol (ARP) layer.
The TCP/IP link layer corresponds to a combination of the data-link and physical layers of the OSI model. The TCP/IP link layer includes network interface card drivers to connect the machine to the physical network, such as an Ethernet network.
In general, the machines that implement the protocol stack in a packet switched network (including, without limitation, source machines, destination machines, packet switches and routers) are computers. Each of these computers includes one or more processors, memories, and input/output ports, and is managed by an operating system.
The computer memory may include a user space and a kernel space. The kernel space is an area of memory which is strictly reserved for running the kernel, device drivers and any kernel extensions. Though some portions of the kernel space may be swapped (paged) out to the disk, some portions are typically never swappable. The user space is a memory area used by all applications and this memory can typically be swapped out at any time depending upon the current system requirements. The user space and the kernel space are distinct. An application usually cannot access the kernel space directly, and similarly kernel code cannot access the user space without checking whether the page is present in memory or swapped out. Applications may, however, use the kernel to access system resources and hardware through system calls, and are therefore thought of as running above, or on top of, the kernel.
Typically, when an incoming packet enters a computer or other hardware device running a protocol stack, the destination of the packet may be some specific code within the kernel, or it may be an application running in the application layer. In any event, the packet will typically be processed by multiple layers of the protocol stack finally arriving at its destination. Similarly, an outgoing packet will typically be processed by multiple layers of the protocol stack before being transmitted onto the network.
In a typical network-capable computer, part of the protocol stack is implemented in kernel space and part is implemented in user space. In the TCP/IP suite, the link, network and transport layers run in kernel space, and the application layer runs in user space. While a packet is being processed in kernel space, pointers to the packet are passed amongst the layers and typically the packet is not recopied for each layer.
When data (e.g., a byte stream) passes between the application layer and the transport layer of the TCP/IP protocol stack, the data moves between user space and kernel space. Since user space and kernel space are separate areas of memory, however, the process of moving data includes copying the data to the destination area and then deleting the original. Thus, in practice, once an incoming packet reaches the top of the kernel protocol stack, its payload is copied to user space to be processed by the application layer of the stack, and the packet is then deleted from kernel space. Similarly, once an outgoing payload has been processed by the application layer in user space, it is copied to kernel space to be processed by the remainder of the protocol stack, and it is then deleted from user space.